package com.ihm.projetihm_v1;

import java.util.List;

import android.app.AlertDialog;
import android.app.Application;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;

import com.ihm.projetihm_v1.nf.Graphe;
import com.ihm.projetihm_v1.nf.LinkedPhoto;
import com.ihm.projetihm_v1.nf.communication.CommunicationFS;
import com.ihm.projetihm_v1.nf.communication.CommunicationHTTP;

/**
 * Represent the application. <br/>
 * Useful to keep information for all the application.
 * 
 * @author Adrien
 *
 */
public class MyApplication
		extends Application
{
	//++++++++//
	// GLOBAL //
	//++++++++//
	
	private boolean mIsInitialized = false;
	public void setInitialized(){ this.mIsInitialized = true; }
	public boolean isInitialized(){ return this.mIsInitialized; }
	
	private List<Graphe<LinkedPhoto>> mMain_GraphsList;
	public List<Graphe<LinkedPhoto>> getMainGraphsList(){ return this.mMain_GraphsList; }
	public void setMainGraphsList(List<Graphe<LinkedPhoto>> graphsList){ this.mMain_GraphsList = graphsList; }
	
	private List<Graphe<LinkedPhoto>> mPhoto_GraphsList;
	public List<Graphe<LinkedPhoto>> getPhotoGraphsList(){ return this.mPhoto_GraphsList; }
	public void setPhotoGraphsList(List<Graphe<LinkedPhoto>> graphsList){ this.mPhoto_GraphsList = graphsList; }
	
	private boolean isMainActivity = true;
	public boolean isMainActivity() { return isMainActivity; }
	public void setIsMainActivity(boolean isMainActivity) {this.isMainActivity = isMainActivity; }
	
	private CommunicationFS mComFS;
	public void setCommunicationFS(CommunicationFS comFS){ this.mComFS = comFS; }
	public CommunicationFS getCommunicationFS(){ return this.mComFS; }
	
	private CommunicationHTTP mComHTTP;
	public void setCommunicationHTTP(CommunicationHTTP comHTTP){ this.mComHTTP = comHTTP; }
	public CommunicationHTTP getCommunicationHTTP(){ return this.mComHTTP; }
	
	/**
	 * An alert message to warn user that app will be ended <br/>
	 * After confirm, the app is closed
	 * @param context the context on which dialog is
	 * @param message a specific message to explain why the app will be closed
	 */
	public void end(Context context, String message)
	{
		OnClickListener dialogClickListener = new OnClickListener() {
		    @Override
		    public void onClick(DialogInterface dialog, int which) {
		        switch (which)
		        {
		        case DialogInterface.BUTTON_NEUTRAL:
		    		System.exit(0);
		            break;
		        }
		    }
		};
    	AlertDialog.Builder builder = new AlertDialog.Builder(context);
    	builder.setMessage(message)
    			.setNeutralButton("Close application", dialogClickListener)
    			.setCancelable(false)
    			.show();
	}

}
